import 'package:flutter/material.dart';
import 'package:rainflutter/config/define.dart';
import 'package:rainflutter/config/routes.dart';
import 'package:rainflutter/main.dart';

class KeyTest extends StatefulWidget {
  @override
  _KeyTestState createState() => _KeyTestState();
}

class _KeyTestState extends State<KeyTest> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  int _count = 0;
  List<String> _names = ['1', '2', '3'];
  String _name = '嚣张';
  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print('----');
    // Image nose =
    //     context.dependOnInheritedWidgetOfExactType<InheritedNose>().asset;

    // nose = Image.asset('assets/images/calendar_summer.png');
    LoginState loginState = InheritedLoginWidget.of(context).loginState;

    return Scaffold(
      appBar: AppBar(title: Text('keyTest')),
      body: Center(
        child: Row(
          children: [
            Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextButton(
                  child: Text(loginState.isLogin ? '登录' : '未登录'),
                  onPressed: () {
                    loginState.isLogin = !loginState.isLogin;
                  },
                ),
                AnimatedSwitcher(
                  duration: const Duration(milliseconds: 500),
                  child: Text(
                    '$_count',
                    // key: UniqueKey(),
                    // style: Theme.of(context).textTheme.headline4,
                  ),
                ),
                RaisedButton(
                  child: const Text(
                    '点击',
                  ),
                  onPressed: () {
                    setState(() {
                      _count++;
                    });
                  },
                ),
                Row(
                  children: [
                    Box(
                      ValueKey(UserInfo('name1')),
                      Colors.red,
                    ),
                    Box(
                      ValueKey(UserInfo('name')),
                      Colors.red,
                    ),
                  ],
                ),
                Row(
                  children: [
                    Box(
                      ObjectKey(UserInfo('name')),
                      Colors.red,
                    ),
                    Box(
                      ObjectKey(UserInfo('name')),
                      Colors.red,
                    ),
                  ],
                ),
                TextButton(
                  onPressed: () {
                    // final Map c = {'1': '2'};
                    // const Map d = {'3': '4'};
                    // c['1'] = 1;
                    // d['3'] = 4;

                    // print(c);
                    // print(d);

                    // aClass aa  = aClass({'1':[1,2,3]});
                    // aa.a['1'] = [];
                    // print(aa.a);
                    // Navigator.of(context).pushNamed('/stateful_builder_test',
                    //     arguments: {
                    //       'name': _name,
                    //       'names': _names
                    //     }).then((value) {
                    //   print('name:$_name \n names:$_names');
                    // });
                    Navigator.of(context).pushNamed(Routes.StatefulBuilderTest);
                  },
                  child: Text('下一个'),
                ),
              ],
            ),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text('name'),
                  TextField(
                    key: ValueKey(1),
                  ),
                  Text('data'),
                  TextField(
                    key: GlobalObjectKey(2),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}

class Box extends StatefulWidget {
  final Color color;

  const Box([Key key, this.color]) : super(key: key);

  @override
  _BoxState createState() => _BoxState();
}

class _BoxState extends State<Box> {
  int _count = 0;
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 100,
      height: 100,
      color: widget.color,
      child: Center(
          child: RaisedButton(
              onPressed: () => setState(() => _count++),
              child: Text(
                _count.toString(),
                style: TextStyle(fontSize: 28),
              ))),
    );
  }
}

class UserInfo {
  final String name;

  UserInfo(this.name);

  @override
  int get hashCode => name.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is UserInfo &&
          runtimeType == other.runtimeType &&
          name == other.name;
}

class aClass {
  final Map a;
  // static const String b = 'bbb';
  // static final c = 'ccc';
  aClass(this.a);
}
